#!/bin/bash

function host_ls
{
    for i in `test_host.txt`
    do
        set timeout 3600
        expect -c "
            spawn ssh-copy-id $ip; 
            expect { 
                "*yes/no" {send "yes\r";exp_continue} 
                "*password:" {send "redhat\r";exp_continue} 
                };
            expect \"]#\" { send \"ls -la \r\" };
            expect \"]#\" { send \"exit \r\" };
            expect eof;
        "
    done
}


function sshcopyid
{
        expect -c "
                set timeout -1;
                spawn ssh-copy-id -f $1;
                expect {
                        \"yes/no\" { send \"yes\r\" ;exp_continue; }
                        \"password:\" { send \"redhat\r\";exp_continue; }
                };
                expect eof;
        "
}
SERVERS 
#for server in $SERVERS;
HOSTS_FILE="test_host.txt"
for server in $(cat $HOSTS_FILE);
do
    if [[ "$server" == "#"* ]]; then
        echo "skip comment line"
    else
        sshcopyid $server
    fi
done